/*package li.dao;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import li.entity.Book;
import li.entity.User;
import li.idao.IBookDao;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

@Repository
public class BookDao implements IBookDao {
	@Resource
	private SessionFactory sessionFactory;

	protected Session getCurrentSession() {
		return sessionFactory.getCurrentSession();
	}

	public List<Book> findOneByBookname(String keyword) {
		// TODO Auto-generated method stub
		Query q = getCurrentSession().createQuery(
				"from Book b where b.bookname = :keyword").setParameter(
				"keyword", keyword);
		return q.list();
	}

	public List<Book> findOneByAuthorname(String keyword) {
		// TODO Auto-generated method stub
		Query q = getCurrentSession().createQuery(
				"from Book b where b.author = :keyword").setParameter(
				"keyword", keyword);
		return q.list();
	}

	public List<Book> findOneByBookindex(String keyword) {
		// TODO Auto-generated method stub
		Query q = getCurrentSession().createQuery(
				"from Book b where b.bookindex = :keyword").setParameter(
				"keyword", keyword);
		return q.list();
	}

	public Book findOneById(long id) {
		// TODO Auto-generated method stub
		return (Book) getCurrentSession().get(Book.class, id);
	}

	public Book findBookById(long id) {
		Book b = (Book) getCurrentSession().get(Book.class, id);
		return b;
	}

	public void returnBook(Book b) {
		// TODO Auto-generated method stub
		b.setBorrowed(false);
		b.setBorrowDate(null);
		b.setReturnDate(null);
		b.setUser(null);
		getCurrentSession().merge(b);
	}

	public void borrowBook(Book b, User u) {
		// TODO Auto-generated method stub
		SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd");
		Date d = new Date();
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		// 借书时间为1个月
		c.add(Calendar.MONTH, 1);
		Date d2 = c.getTime();
		b.setBorrowDate(format.format(d));
		b.setReturnDate(format.format(d2));
		b.setUser(u);
		b.setBorrowed(true);
		b.setBorrowNum(b.getBorrowNum() + 1);
		u.getBooks().add(b);
		getCurrentSession().merge(b);
	}

	public List<Book> findHotBooks(int topn) {
		// TODO Auto-generated method stub
		List<Book> list = getCurrentSession()
				.createQuery("from Book order by borrowNum desc")
				.setFirstResult(0).setMaxResults(topn).list();
		return list;
	}
}
*/